Pierre de Fermat • 1607–1665

Fermat: The Principle That Light Knows Best

In 1662, Fermat claimed light is lazy — it takes the fastest path, not the shortest. That single variational idea became the scaffolding for Lagrangian mechanics, general relativity, and the quantum path integral.

1. Fermat's Principle of Least Time (1662)

Light traveling between two points in a medium of refractive index $n(\mathbf{x})$ follows the path that makes the optical travel time stationary:

$$ \delta T = \delta \int_A^B \frac{n}{c}\, ds = 0 \quad\Longleftrightarrow\quad \delta \int_A^B n\,ds = 0 $$

This is the first variational principle in physics — a full century before Euler and Lagrange formalized the calculus of variations.

For a flat interface between two homogeneous media, minimizing $T(x)= n_1\sqrt{(x-x_A)^2+y_A^2}+n_2\sqrt{(x_B-x)^2+y_B^2}$ gives:

$$ \frac{dT}{dx}=0 \;\Rightarrow\; n_1\frac{x-x_A}{r_1}=n_2\frac{x_B-x}{r_2} \;\Rightarrow\; n_1\sin\theta_1 = n_2\sin\theta_2 $$

— Snell's law, derived not from waves, but from an economy principle.

Refraction Demo

drag A & B
Fermat time
Straight line
Snell check: $n_1\sin\theta_1$ vs $n_2\sin\theta_2$

2. From Fermat to Lagrangian Mechanics

Maupertuis (1744), Euler (1744), and Lagrange (1788) generalized Fermat's idea: all of mechanics follows from $\delta S = 0$ where

$$ S = \int_{t_1}^{t_2} L(\mathbf{q},\dot{\mathbf{q}},t)\,dt, \quad L = T - V $$

For light in an isotropic medium, the Lagrangian is simply $L = n(\mathbf{x})|\dot{\mathbf{x}}|$, so $\int L\,dt = \int n\,ds$ — Fermat's principle is mechanics with a special $L$.

In quantum mechanics, Feynman showed each path contributes amplitude $\exp(iS/\hbar)$. The classical path dominates because nearby paths interfere constructively — stationary phase at $\delta S = 0$.

Least Action Demo

Drag the middle point. The action $S$ is minimal for the true (parabolic) path.

Particle in gravity: $L=\tfrac12 m\dot y^2 - mgy$. Minimum at

3. Fermat in General Relativity

In curved spacetime, null geodesics (light rays) extremize the arrival time as measured by a distant observer — the covariant Fermat principle.

For a static metric $ds^2 = -A(r)c^2dt^2 + B(r)dr^2 + \dots$, the coordinate time is

$$ T = \int \frac{n_{\text{eff}}}{c}dl,\quad n_{\text{eff}} = \sqrt{B/A} $$

Near a mass $M$, $n_{\text{eff}} \approx 1 + \frac{2GM}{c^2r}$. Light slows (coordinate-wise), bending and delaying — gravitational lensing and Shapiro delay.

The deflection angle to first order: $\alpha \approx \frac{4GM}{c^2 b}$.

Gravitational Lensing

Shapiro extra path ≈

4. Fermat's Little Theorem in Physics

Number theory enters the lab, too. For prime $p$ and $a\not\equiv0\pmod p$:

$$ a^{p-1} \equiv 1 \pmod p $$

Applications in physics:

  • RSA & secure comms — physics experiments share data via keys relying on FLT.
  • Shor's algorithm — finds the period $r$ of $a^x\bmod N$, using the fact the multiplicative group mod prime is cyclic of order $p-1$.
  • Monte Carlo — linear congruential generators $x_{n+1}=ax_n+c\bmod m$ use primes for full period, essential in lattice QCD and statistical physics.
  • Quantum phases — $U(1)$ representations, where $e^{2\pi i k/p}$ are $p$-th roots of unity, form the basis of discrete gauge theories.

Modular Exponent Calculator

^ (p−1) mod
3^16 mod 17 = 1

Cycle of powers $a^k \bmod p$ visualizes the cyclic group $\mathbb{Z}_p^\times$.

5. Fermat Point and Minimal Networks

The Fermat–Torricelli point $F$ of a triangle minimizes $PA+PB+PC$. If all angles <120°, the three segments meet at 120°.

Physics reads this as a static equilibrium of three equal tensions, or a Steiner tree, or a soap film junction (Plateau's laws). It is another manifestation of minimizing an integral — now a sum of distances.

Fermat Point Demo

Drag the triangle vertices.

Total at F:
At centroid:

6. Fermat's Last Theorem's Indirect Influence

$$x^n+y^n=z^n \text{ has no non-zero integer solutions for } n>2$$

Wiles' proof (1994) linked elliptic curves to modular forms. Those same modular forms — functions $f(\tau)$ with $f(\frac{a\tau+b}{c\tau+d})=(c\tau+d)^k f(\tau)$ — appear in string theory partition functions

$$ Z(\tau) = \operatorname{Tr} e^{2\pi i \tau (L_0-c/24)} $$

on a torus with modular parameter $\tau$. The $q=e^{2\pi i \tau}$ we met in Euler's pentagonal theorem reappears in black-hole entropy counting and CFT characters. Fermat's marginal note thus points, via modularity, to quantum gravity.

GNU Octave Laboratory

Copy-paste these complete scripts into Octave. They reproduce the interactive demos above.

a) Snell's law from Fermat

n1=1.0; n2=1.5; xA=0; yA=1; xB=2; yB=-1;
x = linspace(0,2,1000);
t = n1*sqrt((x-xA).^2+yA^2) + n2*sqrt((xB-x).^2+yB^2);
[~,i]=min(t); x0=x(i);
theta1=atan((x0-xA)/yA); theta2=atan((xB-x0)/-yB);
printf('n1 sinθ1=%.4f, n2 sinθ2=%.4f\n', n1*sin(theta1), n2*sin(theta2));
plot(x,t); xlabel('interface x'); ylabel('travel time ∝'); grid on;
title(sprintf('Minimum at x=%.3f',x0));

b) Fermat point

A=[0,0]; B=[4,0]; C=[1,3];
f = @(P) norm(P-A)+norm(P-B)+norm(P-C);
P0 = mean([A;B;C]); P = fminsearch(f,P0);
printf('Fermat point: (%.4f, %.4f), sum=%.4f\n', P(1),P(2),f(P));
plot([A(1) B(1) C(1) A(1)],[A(2) B(2) C(2) A(2)],'k-'); hold on;
plot(P(1),P(2),'ro','MarkerSize',8,'LineWidth',2);
plot([P(1) A(1)],[P(2) A(2)],'r--'); plot([P(1) B(1)],[P(2) B(2)],'r--'); plot([P(1) C(1)],[P(2) C(2)],'r--');
axis equal; grid on;

c) Fermat's little theorem test

p=17; a=3;
r = mod(a^(p-1),p)  % should be 1
% find order
ord = find(arrayfun(@(k) mod(a^k,p)==1, 1:p-1),1);
printf('order of %d mod %d is %d (divides %d)\n', a,p,ord,p-1);

d) Least action principle

% particle with L = T-V, find path minimizing action
m=1; g=9.81; y0=0; y1=0; t=linspace(0,1,100);
ym = linspace(-0.5,0.5,41); S=[];
for y = ym
  ypath = [linspace(y0,y,50), linspace(y,y1,50)];
  vy = diff(ypath)./diff(t(1:2));
  T = 0.5*m*mean(vy.^2); V = m*g*mean(ypath);
  S(end+1)= (T-V)*1;
endfor
plot(ym,S,'-o','LineWidth',1.5); xlabel('midpoint height'); ylabel('Action S'); grid on;
[~,i]=min(S); printf('Minimum at y=%.3f (classical path)\n', ym(i));

Continuity: 1662 → Quantum Gravity

Fermat's least time $\delta\int n\,ds=0$ became Euler–Lagrange $\delta\int L\,dt=0$, which became Hilbert's action for GR $\delta\int R\sqrt{-g}\,d^4x=0$, which in the quantum theory weights paths by $e^{iS/\hbar}$.

Hawking's calculation of black-hole radiation evaluates that phase for complex saddle points — the same variational spirit Fermat used to bend a light ray through glass. Modular forms from FLT's proof govern string partition functions $Z(\tau)$, with the same $q=e^{2\pi i\tau}$ Euler studied.

One principle, four centuries: nature is an extremizer, and now we know it's also a phase-sum.

Set in EB Garamond and Inter. Typeset with MathJax. Demos run in your browser — no data leaves your device.